import axios from 'axios'

// create an axios instance
const service = axios.create({
  baseURL: 'http://yangmaogroup.xyz:8888/baby', // url = base url + request url
  withCredentials: false,
  // send cookies when cross-domain requests
  // 注意：withCredentials和后端配置的cross跨域不可同时使用
  timeout: 6000, // request timeout
  crossDomain: true
})

// request拦截器,在请求之前做一些处理
service.interceptors.request.use(config => {
    // 添加请求头
    // console.log('请求拦截成功')\
  console.log('config=>>>')
  console.log(config)
  return config
},
  error => {
    console.log(error) // for debug
    return Promise.reject(error)
  }
)

// 配置成功后的拦截器
service.interceptors.response.use(res => {
  console.log('response====>')
  console.log(res)
  if (res.status === 200) {
    return Promise.resolve(res.data)
  } else {
    return Promise.reject(res.errMsg)
  }
}, error => {
  if (error.response.status) {
    switch (error.response.status) {
      case 401:
        break
      default:
        break
    }
  }
  return Promise.reject(error)
})

export default service
